package com.yuanqi.hnucshop.controller;

import com.yuanqi.hnucshop.service.ex.ServiceException;
import com.yuanqi.hnucshop.utils.JsonResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;

@Controller
public class BaseController {
    public final static int OK = 200;

    @ExceptionHandler(ServiceException.class)
    public JsonResult<Void> handleException(Throwable e){
        JsonResult<Void> jsonResult= new JsonResult<>(e);
        if (e instanceof ServiceException){
            jsonResult.setState(4000);
            jsonResult.setMassage("Service发生错误");
        }
//        else if (e instanceof InsertUserException){
//            jsonResult.setState(5000);
//            jsonResult.setMassage("注册时发生未知错误");
//        }
        return jsonResult;
    }
}
